﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _005ATM机模拟
{
    class BankAccount
    {
        private string _name;//姓名
        private string _accountID;//银行账号
        private float _balance;//余额
        //Todo 14.加入密码属性
        private string _password;//密码
        public string Password
        {
            get { return _password; }
            set { 
                if(value.Length == 6)
                    _password = value; 
                else
                    Console.WriteLine("密码必须是6位!");
            }
        }
        

        //只读属性
        public string Name
        {
            //只能返回字段值
            get { return _name; }
        }
        public string AccountID
        {
            //只能返回字段值
            get { return _accountID; }
        }

        //可读可写属性
        public float Balance
        {
            get { return _balance; }
            set
            {
                if (value > 0)
                    _balance = value;
            }
        }

        /// <summary>
        /// 带参数的构造函数
        /// </summary>
        /// <param name="name">账户名</param>
        /// <param name="accountID">账户ID</param>
        /// <param name="balance">账户余额</param>
        public BankAccount(string name, string accountID, float balance)
        {
            _name = name;
            _accountID = accountID;
            _balance = balance;           
        }

        //打印账户信息
        public void PrintAccountInfo()
        {
            Console.WriteLine("---------账户信息--------");
            Console.WriteLine("账户名:{0}", _name);
            Console.WriteLine("账户ID:{0}", _accountID);
            Console.WriteLine("账户余额:{0}", _balance);
            Console.WriteLine("-------------------------");
        }

    }
}
